package com.vipheyue.educationmp4.tabSample;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.vipheyue.educationmp4.R;
import com.vipheyue.fastlib.adapter.BaseRecyclerAdapter;
import com.vipheyue.fastlib.adapter.BaseRecyclerViewHolder;
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;

import java.util.ArrayList;
import java.util.Arrays;

import butterknife.Bind;
import butterknife.ButterKnife;


@SuppressLint("ValidFragment")
public class SimpleCardFragment extends Fragment {
    private String mTitle;
    @Bind(R.id.recycler)
    RecyclerView recyclerView;
    ArrayList<String> mdata = null;

    public static SimpleCardFragment getInstance(String title) {
        SimpleCardFragment sf = new SimpleCardFragment();
        sf.mTitle = title;
        return sf;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fr_simple_card, null);
        ButterKnife.bind(this, v);
        initData();
        return v;
    }

    private void initData() {
        String[] array = {"1级上", "1级下", "2级上", "2级下", "3级上", "3级下", "4级上", "4级下", "5级上", "5级下"};
        mdata = new ArrayList(Arrays.asList(array));
//        GridLayoutManager layoutManager = new GridLayoutManager(this, 2);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(layoutManager);//设置显示方式
        recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(getActivity())//第三
//                .drawable(R.drawable.sample)///图片
                .drawable(R.drawable.divider)
                .size(0)
                .build());

        BaseRecyclerAdapter adapter = new BaseRecyclerAdapter<String>(getActivity(), mdata, R.layout.activity_item) {
            @Override
            public void init(BaseRecyclerViewHolder holder, String bean, int position) {
                holder.setText(R.id.tv_item, mdata.get(position));
            }
        };
        adapter.setOnItemClickLinster(new BaseRecyclerAdapter.OnItemClickLinster() {
            @Override
            public void onItemClick(View view, int position) {
                Toast.makeText(getActivity(), mdata.get(position), Toast.LENGTH_SHORT).show();
            }
        });
        recyclerView.setAdapter(adapter);//设置适配器

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}